package com.cp.mtq.controller;

import com.cp.mtq.dao.MtqRegionDao;
import com.cp.mtq.entity.MtqRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.Objects;

@RestController
public class Aa {
    @Autowired
    private MtqRegionDao regionDao;

    @GetMapping("/a/a")
    public String a(HttpServletRequest request, Object commands) throws InterruptedException {
        for(int i=0;i<100;i++){
            MtqRegion mtqRegion = regionDao.selectById(8);
            String name = mtqRegion.getName();
            synchronized(name) {
                mtqRegion = regionDao.selectById(8);
                name = mtqRegion.getName();
                mtqRegion.setName(String.valueOf(Integer.parseInt(name)+1));
                regionDao.updateById(mtqRegion);
                System.out.println(Thread.currentThread()+": "+mtqRegion.getName());
            }
        }

        return "ok";
    }
}
